import copy
import os

import config
from enumobjects.general_enum import YesOrNoEnum
from utils.db_util import CreateEngine
from utils.common_util import CommonUtil
import logging
import datetime
from libs.scheduler_wrapper import SchedulerWrapper


class DefaultScheduler(object):
    def __init__(self):
        self.scheduler = SchedulerWrapper()

    @classmethod
    def state(cls):
        session = CreateEngine().get_engine()
        logging.info("开始执行state.")
        session.remove()

    def _init_start(self):
        job_res = self.scheduler.find_job("start")
        if not job_res.is_success or not job_res.data:
            res = self.scheduler.add_job(func=DefaultScheduler.state, minutes=60, job_id="start",
                                         name="start")
            res_message = "成功" if res.is_success else "失败"
            logging.info("系统不存在start的任务, 新建任务%s" % res_message)
            return
        logging.info("系统已存在start的任务")

    def run(self):
        # self.scheduler.remove_job("inform")
        self._init_start()

